package guzb.cnblogs.classloader.third1wrapper;

import guzb.cnblogs.classloader.third.SampleApi;
import guzb.cnblogs.classloader.third.SampleDevice;
import guzb.cnblogs.classloader.thirdapi.v1.DeviceBasicInfoV1;
import guzb.cnblogs.classloader.thirdapi.v1.DeviceFactoryV1;

/**
 * 第一个第三方Jar包的业务层封装配接口实现类
 *
 * @author 顾志兵
 * @mail ipiger@163.com
 * @since 2024-05-21
 */
public class DeviceFactoryV1Impl implements DeviceFactoryV1 {

    private SampleApi sampleApi = new SampleApi();

    @Override
    public DeviceBasicInfoV1 getDeviceInfo(String deviceNo) {
        SampleDevice sampleDevice = sampleApi.checkDevice(deviceNo);
        if (sampleDevice == null) {
            return null;
        }
        return toDeviceBasic(sampleDevice);
    }

    private DeviceBasicInfoV1 toDeviceBasic(SampleDevice sampleDevice) {
        DeviceBasicInfoV1 deviceBasic = new DeviceBasicInfoV1();

        deviceBasic.setDeviceNo(sampleDevice.getSid());
        deviceBasic.setStatus(sampleDevice.getStatus().name());
        deviceBasic.setManager(sampleDevice.getManager());
        deviceBasic.setInboundDate(sampleDevice.getInboundDate());
        deviceBasic.setSocketCount(sampleDevice.getInterfaceConfig().getMonitorPortCount());

        return deviceBasic;
    }
}
